package cn.jb698.codec.msm.zcodec.demo.msm;

import java.util.ArrayList;
import java.util.List;

import cn.jb698.codec.msm.generator.v5base.BcrudCfgObjCreateService;
import cn.jb698.codec.msm.generator.v5base.BcrudCfgObjCreateServiceMysqlImpl;
import cn.jb698.codec.msm.generator.v5base.BcrudCreateCodeFilesImpl;
import cn.jb698.codec.msm.generator.v5base.beans.BcrudCfgTableObj;
import cn.jb698.codec.msm.generator.v5base.beans.BcrudConfigBean;
import cn.jb698.codec.msm.generator.v5base.beans.FileOutputTpltCfg;
import cn.jb698.codec.msm.util.CodecMsmFileOutputTpltUtils;
import cn.jb698.codec.msm.zcodec.demo.CodecPropertiesUtils;

/**
 * 
 * @author Administrator(LiuJianbin)
 * @date 2020-05-02
 */
public class ZCodecMysqlProjxxBcrudUi {

	public static void main(String[] args) throws Exception {

		BcrudConfigBean configBean = init_bcrudConfigBean();

	    // 构建实现类
        BcrudCfgObjCreateService bcrudCfgObjCreateService = new BcrudCfgObjCreateServiceMysqlImpl();
        List<BcrudCfgTableObj> cfgTableList = bcrudCfgObjCreateService.doBcrudCfgTableObjListCreate(configBean);

        {
            // 二次修改表及字段配置数据,覆盖默认生成的配置信息
        }
        // 最终配置输出到Json文件
        bcrudCfgObjCreateService.doCfgTableObjListOutputToJsonFiles(configBean,cfgTableList); // 输出表信息JSON到配置的输出目录

        // 输出创建的代码
        for(BcrudCfgTableObj tableJsBean : cfgTableList ){
            BcrudCreateCodeFilesImpl bcrudCreateCodeFile = new BcrudCreateCodeFilesImpl();

            // 初始化Baomidou配套模板
            List<FileOutputTpltCfg> fileTpltList4Bmd = CodecMsmFileOutputTpltUtils.doFileOutputTpltCfgAppend4Bmd(configBean, configBean.getFileOutputTpltCfgList());
            configBean.setFileOutputTpltCfgList(fileTpltList4Bmd);
            
            // 输出模板 confBean.getProjRootDir()
            bcrudCreateCodeFile.doCodeFilesCreateAndOutput(configBean, tableJsBean); 
        }
	}

	/**
	 * 初始化库配置.
	 */
	private static BcrudConfigBean init_bcrudConfigBean() {

		String default_driverClassName = CodecPropertiesUtils.getPropVal("spring.datasource.driver-class-name");
		String default_connectUrl = CodecPropertiesUtils.getPropVal("spring.datasource.url");
		String default_userName = CodecPropertiesUtils.getPropVal("spring.datasource.username");
		String default_password = CodecPropertiesUtils.getPropVal("spring.datasource.password");

		String basePackageName = "com.cpnyxx.projxx.bcrud";
		String xmlMapperPackage = "mybatis.projxx.mapper";

		String projRootDir = "D:/Develope/workspace/codec/cpnyxx-projxx"; // 目标项目根路径.
		String jsonFile_outDir = projRootDir + "/table_jsons/dbmysql/";
		String codeOutDir = projRootDir + "/src/main/java/";
		String resOutDir = projRootDir + "/src/main/resources/";
		String pageOutDir = projRootDir + "/src/main/webapp/WEB-INF/jsp/temp_aceadmin/bcrud/";

		List<BcrudCfgTableObj> lmtCfgTables = new ArrayList<>();

		lmtCfgTables.add(new BcrudCfgTableObj("dt_mdx_tablexx", "t").doHasSwaggerUi(true).doHasPersistence(true)); // 表xx

		BcrudConfigBean confBean = new BcrudConfigBean();
		confBean.setDbDriverClassName(default_driverClassName);
		confBean.setDbConnectionUrl(default_connectUrl);
		confBean.setDbUserName(default_userName);
		confBean.setDbPassword(default_password);

		confBean.setBasePackageName(basePackageName);
		confBean.setProjRootDir(projRootDir);
		confBean.setJavaCodeRootDir(codeOutDir);
		confBean.setResCodeRootDir(resOutDir);
		confBean.setMapperXmlPackageName(xmlMapperPackage);
		confBean.setPageCodeRootDir(pageOutDir);
		confBean.setJsonFileOutDir(jsonFile_outDir);
		confBean.setCfgTables(lmtCfgTables);
		List<FileOutputTpltCfg> fileOutputTpltCfgList = confBean.getFileOutputTpltCfgList();

		// 添加模板输出-Ctrler-Vo
		FileOutputTpltCfg fileout_admwsModelDtlVo = new FileOutputTpltCfg();
		fileout_admwsModelDtlVo.setTpltFileRes("/codec/proj/src/main/java/projxx/bcrud/ctrler/vo/AdmwsModelDtlVo.java.v5.vm");
		fileout_admwsModelDtlVo.setOutputFileRelDir("/src/main/java/$!{basePackage}/ctrler/vo/");
		fileout_admwsModelDtlVo.setOutputFileName("Admws$!{modelJavaTypeName}DtlVo.java"); 
		fileOutputTpltCfgList.add(fileout_admwsModelDtlVo );

//		// 添加模板输出-Ctrler
//		FileOutputTpltCfg fileout_javaCtrler = new FileOutputTpltCfg();
//		fileout_javaCtrler.setTpltFileRes("/codec/proj/src/main/java/projxx/bcrud/ctrler/SpringMvc_AdmwsModelMgrCtrler.java.v5.vm");
//		fileout_javaCtrler.setOutputFileDir("/src/main/java/$!{basePackage}/ctrler/");
//		fileout_javaCtrler.setOutputFileName("$!{modelJavaTypeName}Ctrler.java"); 
//		fileOutputTpltCfgList.add(fileout_javaCtrler );
		
		return confBean;

	}
	
	

}
